<?php
use think\facade\Session;
use \app\common\model\AdminLog;
use think\facade\View;
//获取用户ID
function AdminId()
{
    $info = session('admin_auth.admin_id');
    return $info;
}
/**
 * 检测管理员是否登录
 * @return integer 0/管理员ID
 */
function is_admin_login()
{
    $admin = Session::get('admin_auth');
    if (empty($admin)) {
        return 0;
    } else {
        return Session::get('admin_auth_sign') == data_auth_sign($admin) ? $admin['admin_id'] : 0;
    }
}
/**
 * 保存后台用户行为
 * @param string $remark 日志备注
 */
function insert_admin_log($remark)
{
    if (session('?admin_auth')) {
        AdminLog::insert([
            'admin_id'    => AdminId(),
            'user_name'   => Session::get('admin_auth.user_name'),
            'user_agent'  => request()->server('HTTP_USER_AGENT'),
            'ip'          => request()->ip(),
            'url'         => request()->url(true),
            'method'      => request()->method(),
            'type'        => request()->type(),
            'param'       => json_encode(request()->param()),
            'remark'      => $remark,
            'create_time' => time(),
        ]);
    }
}
//网站基础配置
function get_base()
{
    $config = app\common\model\System::get_config_by_code('base');
    View::assign('config',$config);//网站配置
}
get_base();

